<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

 class Captcha_model extends CI_Model { 	
    private $vals = array();
    var $baseUrl;
    var $basePath;
    var $captchaImagePath;
    var $captchaImageUrl;
    var $pathtofonts;
    
    public function __construct($configVal = array())
    {
        // Call the Model constructor
        parent::__construct();
        $this->baseUrl  = base_url();
        $this->basePath = realpath(APPPATH.'../');
        $this->captchaImagePath =('/captcha/');
        $this->captchaImageUrl = ('captcha/');
        $this->pathtofonts = $this->basePath . '/system/fonts/verdana.ttf';

        if(!empty($config))
            $this->initialize($configVal);
        else
            $this->vals = array(
                'word'          => '',
                'word_length'   => 6,
                'img_path'      => $this->basePath . $this->captchaImagePath,
                'img_url'       => $this->baseUrl . $this->captchaImageUrl,
                'font_path'     => $this->pathtofonts,
                'img_width'     => '260',
                'img_height'    => 46,
                'expiration'    => 3600);        
    }

    /**
    * initializes the variables
    *
    * @author    Mohammad Jahedur Rahman
    * @access    public
    * @param     array     config
    */
    public function initialize ($configVal = array())
    {
        $this->vals = $configVal;
    } //end function initialize

    //---------------------------------------------------------------

    /**
    * generate the captcha
    *
    * @author     Mohammad Jahedur Rahman
    * @access     public
    * @return     array
    */
    public function generateCaptcha ()
    {
        $cap = create_captcha($this->vals);
        return $cap;
    } 
    //end function generateCaptcha
}
?>